#!/usr/bin/python3.6
# -*- coding: utf-8 -*-
# @Author  : Tina Yu
# @Time    : 2021-4-12 21:19

from typing import List

import pytest

from home_tasks.Calculator import Calculator
from home_tasks.get_yaml_datas import get_add_data


def pytest_collection_modifyitems(items: List):
    # item表示每个测试用例，解决用例名称中文显示问题
    for item in items:
        item.name = item.name.encode("utf-8").decode("unicode-escape")
        item._nodeid = item._nodeid.encode("utf-8").decode("unicode-escape")


@pytest.fixture(scope='class')
def ready_add_testcase():
    print('\n***************开始加法测试**************\n')
    cal = Calculator()
    yield cal
    print("\n\n***************结束加法测试**************")


@pytest.fixture(params=get_add_data()['int_nums'], ids=get_add_data()['int_ids'])
def get_int_nums(request):
    return request.param


@pytest.fixture(params=get_add_data()['float_nums'], ids=get_add_data()['float_ids'])
def get_float_nums(request):
    return request.param


@pytest.fixture(params=get_add_data()['max_nums'], ids=get_add_data()['max_ids'])
def get_max_nums(request):
    return request.param


# 保留此种方式以便后续复习参考
# @pytest.fixture(params=[[0, 0, 0], [0.0000, 0.00, 0.0000]], ids=['整数0', '浮点数0'])
@pytest.fixture(params=get_add_data()['zero_nums'], ids=get_add_data()['zero_ids'])
def get_zero_nums(request):
    return request.param


@pytest.fixture(params=get_add_data()['big_nums'], ids=get_add_data()['big_ids'])
def get_big_nums(request):
    return request.param
